<template>
  <div class="my-table">
    <slot>
      <div class="th">
        <div class="th-td">标题</div>
        <div class="th-td">内容</div>
        <div class="th-td">时间</div>
      </div>

      <div class="content">
        <div class="tr" v-for="item in 10" :key="item">
          <div class="tr-td">标题{{ item }}</div>
          <div class="tr-td">内容{{ item }}</div>
          <div class="tr-td">2022{{ item }}</div>
        </div>
      </div>
    </slot>
  </div>
</template>

<script setup lang="ts">
import { defineProps, toRefs } from "vue"
const props = defineProps({
  width: {
    type: String,
    default: "100%",
  },
  height: {
    type: String,
    default: "200px",
  },
})
const { width, height } = toRefs(props)
</script>

<style lang="scss">
.my-table {
  width: v-bind(width);
  height: v-bind(height);
  box-sizing: border-box;
  transform: scale3d(1, 1, 1);
  border-radius: 4px;
  border-bottom: 1px solid var(--tableBorderColor);
  border: 2px solid var(--borderColor);
  transition: all 0.3s var(--n-bezier);
  margin-bottom: var(--bottom);
  box-shadow: rgba(149, 157, 165, 0.2) 0px 8px 24px;
  .th {
    width: 100%;
    height: 50px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: var(--tableHoverBg);
    color: var(--TextColor);
    transition: all 0.3s var(--n-bezier);
    position: fixed;
    border-bottom: 1px solid var(--tableBorderColor);
    box-sizing: border-box;
    z-index: 2;
    .th-td {
      padding: 12px;
      flex: 1;
      font-weight: bold;
      text-align: center;
    }
  }
  .content {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    padding-top: 50px;
    overflow-y: auto;
    text-align: center;
    .tr {
      width: 100%;
      display: flex;
      justify-content: space-around;
      align-items: center;
      background: var(--BlockBgColor);
      color: var(--TextColor);
      transition: all 0.3s var(--n-bezier);
      border-bottom: 1px solid var(--tableBorderColor);
      box-sizing: border-box;
      &:hover {
        background: var(--tableHoverBg) !important;
      }
      &:nth-child(even) {
        background: var(--tableOddBg);
      }
      .tr-td {
        padding: 12px;
        flex: 1;
        text-align: center;
        line-height: 30px;
        word-break: break-all;
      }
    }
  }
}
</style>
